import java.util.Arrays;

public class Solution661 {
    public int[][] imageSmoother(int[][] img) {
        int[] dx=new int[]{-1,0,1,-1,0,1,-1,0,1};
        int[] dy=new int[]{-1,-1,-1,0,0,0,1,1,1};
        int[][] ans=new int[img.length][img[0].length];
        for (int i=0;i<img.length;i++){
            for (int j=0;j<img[0].length;j++){
                int count=0,sum=0;
                for (int k=0;k<9;k++){
                    if (valid(i+dx[k],j+dy[k],img.length,img[0].length)){
                        sum+=img[i+dx[k]][j+dy[k]];
                        count++;
                    }
                }
                ans[i][j]=sum/count;
            }
        }
        return ans;
    }

    boolean valid(int x,int y,int m,int n){
        return x>=0 && x<m && y>=0 && y<n;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(new Solution661().imageSmoother(new int[][]{{100, 200, 100}, {200, 50, 200}, {100, 200, 100}})));
    }
}
